java -version
gradle -v
#先清空
gradle clean
#现构建项目
gradle build
cd  build/libs/
rm DockerFile
path=$pwd
#获取到jar包名字
jarName=$(ls $path)
#file=$ls $path
touch DockerFile 
chmod 777 DockerFile
echo "${jarName%.*}"
#写入dockerfile文件
echo "
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD $jarName  app.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar">DockerFile
#cp $jarName  /tmp/girlone/
#cp DockerFile /tmp/girlone/
#获取jar包前缀
imageName=${jarName%.*}
{ #try
echo "********stop old container*********"
docker stop $imageName
echo "*********del old container and image*********"
docker rm $imageName
docker rmi $imageName
echo "**********start build image*************"
docker build -f DockerFile -t $imageName  .
echo "***********start run image**************"
docker run -d -p 9002:9002 --name $imageName  $imageName
echo "**********set reboot start***********"
docker update --restart=always $imageName
echo "*********publish success*************"
} || { #catch
#docker build -f DockerFile -t $imageName  .
#docker run -d -p 9002:9002  $imageName   
#docker update --restart=always $imageName
echo "*********publish  error***********"
}
